///////////////////////////////////////////////////
// Election Administration Polarization
// Descriptive Plots and Regressions
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

* Bring in the presidential election analysis data
use "$path/analysis_data/did_election_analysis_data.dta", clear
keep if office=="pres"

* Create a variable capturing the clerk's party
gen p = "R" if party=="REP"
replace p = "D" if party=="DEM"
keep if p!=""

* Plot the relationship between lag and current Dem presidential vote share in
* places with D and R clerks
twoway (scatter vs_dem lag_vs_dem4 if dem==0, mlab(p) mlabp(0) m(none) mlabc("234 68 53%08") mlabsize(small)) ///
	(scatter vs_dem lag_vs_dem4 if dem==1, mlab(p) mlabp(0) m(none) mlabc("76 116 217%08") mlabsize(small)) ///
	(lowess vs_dem lag_vs_dem4 if dem==0, lc("230 19 0") lp(longdash)) ///
	(lowess vs_dem lag_vs_dem4 if dem==1, lc("0 73 209")), ///
	xti("Lag Dem Presidential Vote Share") ///
	yti("Dem Presidential Vote Share") ///
	xsc(r(0 1)) xlab(0(.2)1) ysc(r(0 1)) ylab(0(.2)1) ///
	scale(1.4) ///
	legend(order(4 "Dem Clerk" 3 "Rep Clerk") ring(0) position(4) c(1)) ///
	graphregion(color(white))
graph export "$path/output/dem_pres_vs_simple_plot.pdf", replace

* Plot the residualized Dem presidential vote share for places with
* D vs R clerks
bys dem: sum r_oos_state_year_vs_dem4
twoway (hist r_oos_state_year_vs_dem4 if dem==0, fc("230 19 0%80") lc(none) start(-0.20) width(0.01)) ///
	(hist r_oos_state_year_vs_dem4 if dem==1, fc(none) lc("0 73 209") start(-0.20) width(0.01)), ///
	xti("Residual Dem Pres Vote Share") ///
	text(17 0.054 "Rep Clerks") ///
	text(6.6 -0.087 "Dem Clerks") ///
	scale(1.4) ///
	legend(off) ///
	graphregion(color(white))
graph export "$path/output/resid_dem_pres_vs_hist.pdf", replace
